function clearPath(ctrl)
	startPoint = {}
	endPoint = {}
    waypoints = {}
	finalPoints = {}
end

function clearSquares(ctrl)
    for i,v in ipairs(terrain) do
        explosion1(((v.x+v.w)/2), ((v.y+v.h)/2))
        table.remove(terrain, i)
    end
    terrain = {}
end

function drawPath(ctrl)
    waypoints = {}
	finalPoints = {}
	pathRunning = true
	local tempx1 = 0
	local tempy1 = 0
	local tempx2 = 0
	local tempy2 = 0

	for i,v in ipairs(ctrl.textboxes) do
		if v.text ~= "" then
			if v.name == "Start X" then
				tempx1 = tonumber(v.text)
			elseif v.name == "Start Y" then
				tempy1 = tonumber(v.text)
			elseif v.name == "End X" then
				tempx2 = tonumber(v.text)
			elseif v.name == "End Y" then
				tempy2 = tonumber(v.text)
            end
		end
	end
	findPath(tempx1, tempy1, tempx2, tempy2)
end

function explosion1(x,y)
	local p = love.graphics.newParticleSystem(images.explode, 100)
	p:setEmissionRate(100)
	p:setSpeed(300, 400)
	p:setSize(2, 1)
	p:setColor(220, 105, 20, 255, 194, 30, 18, 0)
	p:setPosition(x,y)
	p:setLifetime(1)
	p:setParticleLife(1)
	p:setDirection(0)
	p:setSpread(360)
	
	p:setRadialAcceleration(-20)
	if math.random(2) == 1 then
		p:setRadialAcceleration(-2000)
		p:setTangentialAcceleration(1000)
	end
	
	table.insert(particles, p)	
	
	return p
end